<?php

class WebUser extends CWebUser
{
	private $_model;
	
    public function login($identity, $duration = 0) {
        parent::login($identity, $duration);
    	$this->setUserInfo($identity->getModel());
    }
    
    public function getModel()
    {
    	if($this->_model)
    	{
    		return $this->_model;
    	}
    	$user = User::model()->findByPk($this->id);
    	$this->_model = $user;
    	return $user;
    }
    
    public function setUserInfo($model)
    {
    	if($this->isGuest)
    	{
    		return false;
    	}
    	$this->_model = $model;
    	$this->setState('isAdmin',($this->_model->user_type == 1) ? TRUE : FALSE);
    	$this->setState('userInfo',$this->_model->attributes);
    }
}
